<--- %%NOBANNER%% --> zerodata.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| This macro converts any numeric SAS variable that has a missing    |
| value to a ZERO.                                                   |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| Parameter: the name of the SAS Dataset to convert numeric missing  |
|            data to zeroes.                                         |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %zerodata(indata=work.test); - sample call of macro;      |
| Usage:   %zerodata(indata=&syslast, outdata=&indata);              |
\-------------------<-- End of Files Created-->---------------------*/
%macro zerodata (indata, outdata);
/*--------------------------------------------\
| Author:   Duo Zhou;                         |
| Created:  8-27-2001 9:12pm;                 |
| Modified: 12-12-2001 8:12pm;                |
| Purpose:  change numeric missing values to  |
|           zeros (0's);                      |
\--------------------------------------------*/
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&indata))))),%str(DATA=))) %then %do;
   %let indata=%qscan(%quote(&indata), 2, %str(=));
%end;
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&outdata))))),%str(DATA=))) %then %do;
   %let outdata=%qscan(%quote(&outdata), 2, %str(=));
%end;
%else %if (%quote(&outdata) eq) %then %do;
   %let outdata=&indata;
%end;
%if %sysfunc(exist(&indata)) %then %do ;
   data &outdata ( drop = __i ) ;
      set &indata ;
      array __nums (*) _numeric_ ;
      do __i = 1 to dim ( __nums ) ;
         if (__nums [__i]) = . then __nums[__i] = 0 ;
      end ;
   run ;
%end ;
%else %put ==> Alert! (ZERODATA) dataset "&indata" does not exist. ;
%mend zerodata ;